<?php
namespace web\admin\controller;

/**
 * 货品列表
 */
class Itemlist extends Common{
	private $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Itemlist();
	}

	public function index(){
		if(IS_POST){
//			p($_POST);die;
			if(!$this->db->store()){
				//获取错误
				message($this->db->getError(),'back','error');
			}else{
				message('添加成功',u('index',['sid'=>$_POST['sid']]),'success');
			}
		}
		$sid = q('get.sid',0,'intval');
		$itemlistData = $this->db->where('sid',$sid)->get();
		//1.在类型属性中根据class和tid筛选出规格数据


		$tid = Db::table('vivo_shop')->where('sid',$sid)->pluck('tid');
		$data = Db::table('vivo_typeattr')->where('taclass',1)->where('tid',$tid)->get();
		foreach($data as $k=>$v)
		{
			$data[$k]['select'] = Db::table('vivo_shopattr')->where('sid',$sid)->where('taid',$v['taid'])->get();
		}
		View::with('data',$data);
		foreach ($itemlistData as $k=>$v){
			$combine = explode(',',$v['combine']);
			foreach ($combine as $kk=>$vv){
				$combine[$kk]= Db::table('vivo_shopattr')->where('said',$vv)->pluck('stvalue');

			}
			$itemlistData[$k]['combine']=$combine;
		}
		View::with('itemlistData',$itemlistData);
		View::make();
	}
	/**
	 * 删除
	 */
	public function del(){
		$ilid = q('get.ilid',0,'intval');
		$sid = q('get.sid',0,'intval');
		$this->db->where('ilid',$ilid)->delete();
		message('操作成功',u('index',['sid'=>$sid]),'success');
	}

}
